/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package controller;

import java.beans.Statement;
import java.io.*;
import java.sql.*;
import java.util.ArrayList;
import java.util.logging.*;
import javax.servlet.*;
import movie.Film;
import movie.connection;

/**
 *
 * @author Satellite
 */
public class cariServlet extends GenericServlet {

    public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException {
        String keyword = null;
        keyword = req.getParameter("search");
        ArrayList pakets = new ArrayList();

        Connection connection = new connection().getDBConnection();

        String sql = "SELECT * from movie where nama LIKE '" + keyword + "'";

        try {
            java.sql.Statement s = connection.createStatement();
            ResultSet rs = s.executeQuery(sql);
            while (rs.next()) {
                Film pk = new Film();
                pk.judul_film = rs.getString(1);
                pk.sinopsisFilm = rs.getString(2);
                pk.lokasiFilm = rs.getString(3);
                pk.trailer = rs.getString(4);
                pk.poster = rs.getString(5);
                pk.harga = rs.getString(6);
                pakets.add(pk);
            }
            rs.close();
            s.close();
            connection.close();
        } catch (SQLException e) {
            System.out.println("SQL statement is not executed!");
        }

        req.setAttribute("pakets", pakets);
        RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/HalamanPencarian.jsp");
        dispatcher.forward(req, res);
    }
}
